<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
if($_RQ['op']=='main'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$sum = pdo_count('jy_merch_game_item',$params);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
	$return['member']=$member;
	
	set_html('title','帖子列表');
	$return['sum']=$sum;
	$return['params']=array();
    $return['list']=array();
	exi($return);

}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
			$list=pdo_getall('jy_merch_game_item',$params,$fields,'','likes desc, id desc');
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}else{
			$pindex = max(1, intval($_RQ['page']));
			$psize = 10;
			$list=pdo_getslice('jy_merch_game_item',$params,array($pindex,$psize),$total,$fields,'','id desc');
	}
	$allitemgame=$this->allitemgame;
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			if($item['status']==0){
				$item['statustitle']='审核中';
			}elseif($item['status']==1){
				$item['statustitle']='审核通过';
			}else{
				$item['statustitle']='不通过';
			}
			$item['content']=json_decode($item['content'],true);
			if(!$item['price'] || $item['price']<0){
				$item['goods']=json_decode($item['goods'],true);
				$item['price']=$item['goods'][0]['price'];
			}
			$item['typename']=$allitemgame[$item['gamename']]['title'];
			$item['onlinetime']=$item['onlinetime']?$item['onlinetime']:$item['createtime']+7*24*3600;
			$item['endstatus']=$item['onlinetime']>time()?1:0;
			$item['onlinetime']=date('Y-m-d H:i:s',$item['onlinetime']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['typetitle']=$this->itemtypes[$item['type']];
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
            $item['member']['avatar']=tomedia($item['member']['avatar']);
			$item['jielinum']=pdo_count('jy_merch_game_order',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
			$item['likenumn']=pdo_count('jy_merch_game_item_like',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
			$item['jieli']=pdo_getall('jy_merch_game_order',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'','createtime desc');
			if($item['msg']){
				foreach($item['msg'] as &$m){
					$m['createtime'] = date('Y-m-d H:i',$m['createtime']);
					$m['member'] = pdo_get('core_members',array('id'=>$m['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				}
			}
			if($item['jieli']){
				foreach($item['jieli'] as &$j){
					$j['createtime'] = date('Y-m-d H:i',$j['createtime']);
					$j['member'] = pdo_get('core_members',array('id'=>$j['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				}
			}
		}
	}
	else{
		$sum=0;
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='del'){	
	if(!$_RQ['id']){
		exi('活动不存在哦！','error');
	}	
	pdo_delete('jy_merch_game_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！','','/myitem/');
}
if($_RQ['op']=='open'){
	$postdata=get_postdata();
	$id=$postdata['id'];
	if(!$id){
		exi('获得不存在哦！'.$id,'error');
	}
	$isshow=pdo_getcolumn('jy_merch_game_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'isshow');
	if($isshow){
		pdo_update('jy_merch_game_item',array('isshow'=>0),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		pdo_update('jy_merch_game_item',array('isshow'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}
	exi('操作成功');
}